Belgelerim/ceng_491/implementation/doxygen/TraffEdu_Developers_Manual_Reference_ToSource/OsgWindows.cpp

Go to the documentation of this file.
00001 
00002 OSGWindows::OSGWindows()
00003 {
00004         
00005         currentFrameNum = -1;
00006         viewer = new osgProducer::Viewer();
00007         clickedFrameId=-1;
00008         onDisplayFrameId=-1;
00009         mainRoot = new osg::Group;
00010         textRoot = new osg::Group;
00011         mainRoot->addChild(textRoot.get());
00012 
00013         eventHandler = new GUICommandManager();
00014         eventHandler->setUndoLevel(30);
00015 
00016         m_b_AudioInserted = false;
00017         
00018 }
00019 
00020 int OSGWindows::getCurrentFrameId()
00021 {
00022         return currentFrameNum;
00023 }
00024 
00025 void OSGWindows::setCurrentFrameId(int id)
00026 {
00027         currentFrameNum = id;
00028 }
00029 void OSGWindows::setClickedFrameId(int id)
00030 {
00031         clickedFrameId = id;
00032 }
00033 void OSGWindows::setOnDisplayFrameId(int id)
00034 {
00035         onDisplayFrameId = id;
00036 }
00037 
00038 void OSGWindows::addObject(TraffEduObject* obj)
00039 {
00040         objects.push_back(obj);
00041 }
00042 vector<TraffEduObject*> OSGWindows::getObjects(void)
00043 {
00044         return objects;
00045 }
00046 
00047 vector<Frame*>& OSGWindows::getFrames(void)
00048 {
00049         return frames;
00050 }
00051 
00052 
00053 void OSGWindows::doDeleteGeode(TraffEduObject* obj)
00054 {
00055         objects.at(obj->getObjectId())->hide(mainRoot);
00056         objects.at(obj->getObjectId())->setCondition('d');
00057 }
00058 
00059 
00060 void OSGWindows::doAddGeode(TraffEduObject* obj)
00061 {
00062         if(obj->getIsBeforeCreated())
00063                 objects.at(obj->getObjectId())->display(mainRoot);
00064         else
00065         {
00066                 
00067         objects.at(obj->getObjectId())->draw(mainRoot);
00068         }
00069         objects.at(obj->getObjectId())->setCondition('a'); 
00070 }
00071 
00072 osg::ref_ptr<osg::Group> OSGWindows::getConstantRoot()
00073 {
00074         return mainRoot;
00075 }
00076 
00077 osg::ref_ptr<osg::Group> OSGWindows::getTextRoot()
00078 {
00079         return textRoot;
00080 }
00081 
00082 int OSGWindows::sizeOfFrames()
00083 {
00084         return (int)frames.size();
00085 }
00086 
00087 Frame* OSGWindows::getCurrentFrame()
00088 {
00089         for(int i=0;i<(int)frames.size();i++)
00090         {
00091                 if(frames.at(i)->getFrameId() == currentFrameNum)
00092                         break;
00093         }
00094 
00095         return frames.at(i);
00096 }
00097 
00098 void OSGWindows::sortFrames(){ 
00099         int j,i,key;
00100         int length=frames.size();
00101         Frame * temp;
00102 
00103         for( j=1;j<length;++j){
00104                 temp=frames[j];
00105                 key=frames[j]->getFrameId();
00106                 i=j-1;
00107                 while(i>=0 && frames[i]->getFrameId()>key){
00108                         frames[i+1]=frames[i];
00109                         i-=1;
00110                 }
00111                 frames[i+1]=temp;
00112         }
00113 }
00114 
00115 int OSGWindows::returnIndex(int frameID){
00116         int length=sizeOfFrames();
00117         for(int i=0; i<length;++i){
00118                 if(frameID==(frames[i]->getFrameId()))
00119                         return i;
00120         }
00121         return -1;
00122 
00123 }
00124 
00125 void OSGWindows::clickedOnAFrame(int frameId)
00126 {
00127 
00128         clickedFrameId = frameId;
00129         int oldonDisplayFrameId=onDisplayFrameId;
00130         onDisplayFrameId=findReferenceFrame(frameId);
00131 
00132         if(onDisplayFrameId == frameId)
00133                 changeCurrentFrame(onDisplayFrameId,oldonDisplayFrameId);
00134         else
00135                 displayAFrame(onDisplayFrameId);
00136 }
00137 
00138 
00139 void OSGWindows::changeCurrentFrame(int frameId,int oldonDisplayFrameId)
00140 {       
00141         currentFrameNum=frameId;
00142         onDisplayFrameId=oldonDisplayFrameId;
00143         int size=(int)objects.size();
00144         for(int i=0;i<size;i++)
00145         {
00146                 if(objects.at(i)->getObjectType() == VEHICLE)
00147                 {
00148                         if(objects.at(i)->getCondition()=='a'){
00149                                 objects.at(i)->draw(osgwind->getConstantRoot());
00150                         }
00151                 }
00152                 
00153                 if(objects.at(i)->getObjectType() == LIGHT)
00154                 {
00155                         if(objects.at(i)->getCondition()=='a'){
00156                                 objects.at(i)->draw(osgwind->getConstantRoot());        
00157                         }
00158                 }
00159 
00160         }
00161 
00162         for(int i=0;i<textArray.size(); i++)
00163         {
00164                 if(textArray[i]->frameNum != currentFrameNum)
00165                 {
00166                         int ij=textRoot->getNumChildren();
00167                         for(int i=0;i<ij;i++){
00168                                 textRoot->removeChild(0,1);
00169                                 
00170                         }
00171                 }
00172         }
00173         for(int i=0;i<textArray.size(); i++)
00174         {
00175                 if(textArray[i]->frameNum == currentFrameNum)
00176                 {
00177                         textRoot->addChild(textArray[i]->textGroup.get());
00178                         break;
00179                 }
00180         }
00181         onDisplayFrameId=currentFrameNum;
00182         
00183 }
00184 
00185 void OSGWindows::displayAFrame(int frameId)
00186 {
00187         
00188         currentFrameNum = -1;
00189 
00190         int size=(int)frames.size();
00191         int i;
00192         for(i=0;i<size;i++)
00193         {
00194                 if(frames.at(i)->getFrameId()==frameId)
00195                         break;
00196         }
00197         for(int i=0;i<textArray.size(); i++)
00198         {
00199                 if(textArray[i]->frameNum != currentFrameNum)
00200                 {
00201                         int ij=textRoot->getNumChildren();
00202                         for(int i=0;i<ij;i++){
00203                                 textRoot->removeChild(0,1);
00204                                 
00205                         }
00206                 }
00207         }       
00208 }
00209 
00210 vector<textperFrame* >& OSGWindows::getTextArray()
00211 {
00212         return textArray;
00213 }
00214 
00215 void OSGWindows::addNewFrame()
00216 {
00217 
00218         currentFrameNum = clickedFrameId;
00219         
00220         Frame* frame = new Frame(clickedFrameId);
00221         frames.push_back(frame);
00222         sortFrames();
00223         
00224         int size=(int)objects.size();
00225         for(int i=0;i<size;i++)
00226         {
00227                 if(objects.at(i)->getObjectType() == VEHICLE)
00228                 {
00229                         if(objects.at(i)->getCondition()=='a'){
00230                         objects.at(i)->addObjectPAT(currentFrameNum);
00231                         objects.at(i)->draw(osgwind->getConstantRoot());
00232 
00233                         }
00234                         
00235                 }
00236 
00237                 if(objects.at(i)->getObjectType() == LIGHT)
00238                 {
00239                         if(objects.at(i)->getCondition()=='a'){
00240                                 ((TrafficLight*)(objects.at(i)))->setNewFramesLightColor(onDisplayFrameId,clickedFrameId);
00241                                 objects.at(i)->draw(osgwind->getConstantRoot());
00242                                 
00243                         }
00244                         
00245                 }
00246         }
00247         onDisplayFrameId = clickedFrameId; 
00248 
00249 }
00250 
00251 void OSGWindows::loadFrame(int clickedFrame)
00252 {
00253 
00254         currentFrameNum = clickedFrame;
00255         sortFrames();
00256         
00257         int size=(int)objects.size();
00258         for(int i=0;i<size;i++)
00259         {
00260                 if(objects.at(i)->getObjectType() == VEHICLE)
00261                 {
00262                         if(objects.at(i)->getCondition()=='a'){
00263                         objects.at(i)->draw(osgwind->getConstantRoot());
00264 
00265                         }
00266                         
00267                 }
00268 
00269         }
00270         onDisplayFrameId = clickedFrame; 
00271 
00272 }
00273 
00274 void OSGWindows::deleteFrame()
00275 {
00276         
00277         int size=(int)frames.size();
00278         if(size==1)
00279         {
00280                 mainRoot->removeChild(2,mainRoot->getNumChildren());
00281                 
00282                 if(objects.size()>0)
00283                 {
00284                 objects.at(0)->resetObjectId();
00285                 objects.clear();
00286                 }
00287 
00288                 eventHandler->Clear();
00289                 frames.clear();
00290                 currentFrameNum = -1;
00291                 onDisplayFrameId = -1;
00292                 
00293          return;
00294         }
00295         int length=objects.size();
00296         for(int i=0;i<length;i++)
00297         {
00298                 if(objects.at(i)->getObjectType() == VEHICLE)
00299                 {
00300                         objects.at(i)->deleteObjectPAT(currentFrameNum);
00301                 }
00302         }
00303 
00304         
00305         for(int i=0;i<size;i++)
00306         {
00307 
00308                 if(frames.at(i)->getFrameId() == currentFrameNum)
00309                 {
00310                         frames.erase(frames.begin()+i,frames.begin()+(i+1));
00311                         break;
00312                 }
00313         }
00314         sortFrames();
00315         
00316         onDisplayFrameId=findReferenceFrame(clickedFrameId);
00317         currentFrameNum=onDisplayFrameId;
00318         for(int i=0;i<length;i++)
00319         {
00320                 if(objects.at(i)->getObjectType() == VEHICLE)
00321                 {
00322                         if(objects.at(i)->getCondition()=='a'){
00323                         objects.at(i)->draw(osgwind->getConstantRoot());
00324 
00325                         }
00326 
00327                 }
00328 
00329                 if(objects.at(i)->getObjectType() == LIGHT)
00330                 {
00331                         if(objects.at(i)->getCondition()=='a'){
00332                         ((TrafficLight*)(objects.at(i)))->setNewFramesLightColor(onDisplayFrameId,clickedFrameId);
00333                                 objects.at(i)->draw(osgwind->getConstantRoot());
00334 
00335 
00336                         }
00337 
00338                 }
00339 
00340         }
00341         
00342         currentFrameNum=-1;
00343         
00344 }
00345 
00346 int OSGWindows::findReferenceFrame(int frameId)
00347 {
00348         
00349         int referenceFrameId=-1;
00350         int size= frames.size();
00351         for(int i=0;i<size;i++)
00352         {
00353                 int tmpId = frames.at(i)->getFrameId();
00354                 
00355                 if(tmpId < frameId)
00356                 {
00357                         referenceFrameId = tmpId;
00358                         continue;
00359                 }
00360                 else
00361                         
00362                 {
00363                         referenceFrameId = tmpId;
00364                         break;
00365                 }
00366         }
00367         
00368         return referenceFrameId;
00369 }
00370 
00371 bool OSGWindows::canAddNewFrame()
00372 {
00373         if((currentFrameNum == clickedFrameId && (int)frames.size() != 0) || clickedFrameId == -1)
00374                 return FALSE;
00375         else
00376                 return TRUE;
00377 }
00378 
00379 
00380 bool OSGWindows::canDeleteAFrame()
00381 {
00382         if(currentFrameNum == clickedFrameId && (int)frames.size() != 0 )
00383                 return TRUE;
00384         else
00385                 return FALSE;
00386 }
00387 
00388 int OSGWindows::getOnDisplayFrameId()
00389 {
00390         return onDisplayFrameId;
00391 }
00392 
00393 
00394 void OSGWindows::addCommandDelete()
00395 {
00396         
00397         
00398         CommandDelete* pCommand = new CommandDelete(osgwind);
00399         eventHandler->DoCommand(pCommand);
00400 
00401 }
00402 
00403 
00404 void OSGWindows::addCommandDelete(TraffEduObject* obj)
00405 {
00406         
00407         
00408         CommandDelete* pCommand = new CommandDelete(osgwind,obj);
00409         eventHandler->DoCommand(pCommand);
00410 
00411 }
00412 
00413 void OSGWindows::addCommandCut()
00414 {
00415         
00416         CommandCut* pCommand = new CommandCut(osgwind);
00417         eventHandler->DoCommand(pCommand);
00418 }
00419 
00420 void OSGWindows::addCommandCut(TraffEduObject* obj)
00421 {
00422         
00423         CommandCut* pCommand = new CommandCut(osgwind,obj);
00424         eventHandler->DoCommand(pCommand);
00425 }
00426 
00427 void OSGWindows::addCommandCopy(void)
00428 {
00429         CommandCopy* pCommand = new CommandCopy(osgwind);
00430         pCommand->execute();
00431 }
00432 
00433 void OSGWindows::addCommandCopy(TraffEduObject* obj)
00434 {
00435         CommandCopy* pCommand = new CommandCopy(osgwind,obj);
00436         pCommand->execute();
00437 }
00438 
00439 void OSGWindows::addCommandPaste(osg::Vec3 pos)
00440 {
00441         
00442         CommandPaste* pCommand = new CommandPaste(pos,osgwind);
00443         eventHandler->DoCommand(pCommand);
00444 }
00445 
00446 void OSGWindows::addCommandSelect(int isMultipleSelection,TraffEduObject* obj)
00447 {
00448 
00449         CommandSelect* pCommand = new CommandSelect(isMultipleSelection,obj,osgwind);
00450         pCommand->execute();
00451 }
00452 
00453 void OSGWindows::addCommandSelectAll()
00454 {
00455         
00456         CommandSelectAll* pCommand = new CommandSelectAll(osgwind);
00457         pCommand->execute();
00458 }
00459 
00460 
00461 void OSGWindows::addCommandDeselectAll()
00462 {
00463         
00464         CommandDeselectAll* pCommand = new CommandDeselectAll(osgwind);
00465         pCommand->execute();
00466 }
00467 
00468 void OSGWindows::addCommandDeselect(TraffEduObject* obj)
00469 {
00470         
00471         CommandDeselect* pCommand = new CommandDeselect(obj,osgwind);
00472         pCommand->execute();
00473 }
00474 
00475 void OSGWindows::addCommandInsertTrafficLight(osg::Vec3 pos,TrafficLightTypes newType,
00476                                                                                  TrafficLightColor newColor,
00477                                                                      TrafficLightColor newArrowColor)
00478 {
00479         
00480         CommandInsertTrafficLight* pCommand = new CommandInsertTrafficLight(pos,osgwind,newType,newColor,newArrowColor);
00481         eventHandler->DoCommand(pCommand);      
00482 }
00483 
00484 void OSGWindows::addCommandInsertTrafficSign(osg::Vec3 pos,TrafficSignTypes newType)
00485 {
00486         
00487 
00488         CommandInsertTrafficSign* pCommand = new CommandInsertTrafficSign(pos,osgwind,newType);
00489         
00490         eventHandler->DoCommand(pCommand);      
00491 }
00492 
00493 
00494 void OSGWindows::addCommandInsertVehicle(osg::Vec3 pos,string pathname,float scale)
00495 {
00496         
00497         CommandInsertVehicle* pCommand = new CommandInsertVehicle(pos,osgwind,pathname,scale);
00498         eventHandler->DoCommand(pCommand);      
00499 }
00500 
00501 void OSGWindows::addCommandInsertEnvObj(osg::Vec3 pos,string pathname,float scale)
00502 {
00503         
00504         CommandInsertEnvObj* pCommand = new CommandInsertEnvObj(pos,osgwind,pathname,scale);
00505         eventHandler->DoCommand(pCommand);      
00506 }
00507 
00508 void OSGWindows::addCommandRotate(float angle)
00509 {
00510         
00511         CommandRotate* pCommand = new CommandRotate(angle,osgwind);
00512         eventHandler->DoCommand(pCommand);
00513 }
00514 
00515 void OSGWindows::addCommandRotate(float angle,TraffEduObject* obj)
00516 {
00517         
00518         CommandRotate* pCommand = new CommandRotate(angle,osgwind,obj);
00519         eventHandler->DoCommand(pCommand);
00520 }
00521 
00522 void OSGWindows::addCommandTranslate(TraffEduObject* obj,osg::Vec3 old_position,osg::Vec3 new_position)
00523 {
00524         CommandTranslate* pCommand = new CommandTranslate(obj,old_position,new_position,osgwind);
00525         eventHandler->DoCommand(pCommand);
00526 }
00527 
00528 bool OSGWindows::canUndo()
00529 {
00530         
00531         return eventHandler->CanUndo();
00532 }
00533 
00534 bool OSGWindows::canRedo()
00535 {
00536         return eventHandler->CanRedo();
00537 }
00538 
00539 void OSGWindows::undo()
00540 {
00541         eventHandler->Undo();
00542 }
00543 
00544 void OSGWindows::redo()
00545 {
00546         eventHandler->Redo();
00547 }
00548 
00549 BOOL OSGWindows::isModified()
00550 {
00551         return (eventHandler->IsDirty() ? TRUE : FALSE);
00552 }
00553 
00554 
00555 void OSGWindows::setSelectedObjects(TraffEduObject* obj)
00556 {
00557         
00558         selectedObjects.push_back(obj);
00559 }
00560 
00561 vector<TraffEduObject*> OSGWindows::getSelectedObjects(void)
00562 {
00563         return selectedObjects;
00564 }
00565 
00566 void OSGWindows::setCutObjects(void)
00567 {
00568         for(int i=0;i<(int)selectedObjects.size();i++)
00569         {
00570                 cutObjects.push_back(selectedObjects.at(i));
00571         }
00572         selectedObjects.clear();
00573 }
00574 
00575 void OSGWindows::setCutObjects(TraffEduObject* obj)
00576 {
00577         cutObjects.push_back(obj);
00578 }
00579 
00580 vector<TraffEduObject*> OSGWindows::getCutObjects(void)
00581 {
00582         return cutObjects;
00583 }
00584 
00585 void OSGWindows::setCopiedObjects(void)
00586 {
00587         for(int i=0;i<(int)selectedObjects.size();i++)
00588         {
00589                 copiedObjects.push_back(selectedObjects.at(i));
00590         }
00591         
00592 }
00593 
00594 void OSGWindows::setCopiedObjects(TraffEduObject* obj)
00595 {
00596         copiedObjects.push_back(obj);
00597 }
00598 
00599 vector<TraffEduObject*> OSGWindows::getCopiedObjects(void)
00600 {
00601         return copiedObjects;
00602 }
00603 
00604 void OSGWindows::clearSelectedObjects(void)
00605 {
00606         selectedObjects.clear();
00607 }
00608 
00609 void OSGWindows::clearFrames(void)
00610 {
00611         frames.clear();
00612 }
00613 
00614 void OSGWindows::clearCopiedObjects(void)
00615 {
00616         copiedObjects.clear();
00617 }
00618 
00619 void OSGWindows::clearCutObjects(void)
00620 {
00621         cutObjects.clear();
00622 }
00623 
00624 void OSGWindows::fillSelectedObjects(void)
00625 {
00626         
00627         for(int i=0;i<(int)osgwind->getObjects().size();i++)
00628         {
00629                 if(osgwind->getObjects().at(i)->getCondition() == 'a')
00630                         setSelectedObjects(osgwind->getObjects().at(i));
00631         }
00632 }
00633 
00634 void OSGWindows::dropUnselectedObject(TraffEduObject* obj)
00635 {
00636         int size = (int)selectedObjects.size();
00637         for(int i=0 ; i<size;i++)
00638         {
00639                 if(selectedObjects.at(i)->getObjectId() == obj->getObjectId() && 
00640                         selectedObjects.at(i)->getObjectType() == obj->getObjectType())
00641                 {
00642                 selectedObjects.erase( selectedObjects.begin()+i, selectedObjects.begin()+(i+1) );
00643                         break;
00644                 }
00645         }
00646 }
00647 
00648 void OSGWindows::clearObjects() 
00649 {
00650         objects.clear();
00651 }
00652 
00653 bool OSGWindows::getAudioFlag()
00654 {
00655         return m_b_AudioInserted;
00656 }

Generated on Sun May 28 18:54:09 2006 for TraffEdu by  doxygen 1.4.6-NO